package com.zhao.sqltest;

import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class InsertDataActivity extends Activity{
    private String name;
    private String phone;
    private SQLiteDatabase db;
    private EditText et_name;
    private EditText et_phone;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_updata_data);
        init();
    }
    private  void init(){
        db=MainActivity.getDb();
        name="";
        phone="";
        et_name=(EditText)findViewById(R.id.et_name);
        et_phone=(EditText)findViewById(R.id.et_phone);
    }

    /**
     * 数据库的插入
     * 将两个EditView（Name 和 Phone）中的数据添加到数据库中
     * @param v
     */
    public void save (View v){
        name=et_name.getText().toString();
        phone=et_phone.getText().toString();
        /***************************
         **数据库的插入 insert
         ***************************/
        ContentValues cv=new ContentValues();
        cv.put("name",name);
        cv.put("phone",phone);
        db.insert("contacter", "", cv);
        Toast.makeText(InsertDataActivity.this,"添加成功",Toast.LENGTH_SHORT).show();
    }
}
